#include "widget.h"
#include "ui_widget.h"
#include <QListWidget>
#include <QListWidgetItem>
#include <QDebug>


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
//    ui->listWidget->addItem("C++");
//    ui->listWidget->addItem("Java");
//    ui->listWidget->addItem("Python");
    ui->listWidget->addItem(new QListWidgetItem("C++"));
    ui->listWidget->addItem(new QListWidgetItem("Java"));
    ui->listWidget->addItem(new QListWidgetItem("Python"));
}

void Widget::on_pushButton_clicked()
{
    // 获取编辑框内的项目
    QString item = ui->lineEdit->text();
    ui->listWidget->addItem(item);
    ui->lineEdit->setText(" ");
}

void Widget::on_pushButton_2_clicked()
{
    // 获取当前行
    int curRow = ui->listWidget->currentRow();
    qDebug() << "curRow = " << curRow;
    // 删除当前行
    ui->listWidget->takeItem(curRow);

}

void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if(current != nullptr && previous != nullptr)
    {
        qDebug() << "当前所选 " <<  current->text()     << ", 之前所选 " << previous->text();
    }
}


Widget::~Widget()
{
    delete ui;
}
